//
//  UILabel+XYAdd.m
//  PeiJue
//
//  Created by lxy on 2017/9/28.
//  Copyright © 2017年 lixiya. All rights reserved.
//

#import "UILabel+XYAdd.h"

@implementation UILabel (XYAdd)

+ (UILabel *)labelWithFont:(UIFont *)font textColor:(UIColor *)textColor {
    return [self labelWithFont:font textColor:textColor textAlignment:NSTextAlignmentLeft];
}

+ (UILabel *)labelWithFont:(UIFont *)font textColor:(UIColor *)textColor textAlignment:(NSTextAlignment)textAlignment{
    UILabel *lab = [[UILabel alloc] init];
    lab.textColor = textColor;
    lab.font = font;
    lab.textAlignment = textAlignment;
    return lab;
}


- (void)setText:(NSString*)text wordSpacing:(CGFloat)space {
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:text attributes:@{NSKernAttributeName:@(space)}];
    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineBreakMode:NSLineBreakByWordWrapping];
    [paragraphStyle setAlignment:NSTextAlignmentJustified];
    [paragraphStyle setBaseWritingDirection:NSWritingDirectionNatural];
     
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [text length])];
    
    self.attributedText = attributedString;
}

@end
